package com.wangshuo.webadmin.common;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.wangshuo.webadmin.entity.LeaseAgreement;
import com.wangshuo.webadmin.service.LeaseAgreementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class ScheduledTasks {
    @Autowired
    private LeaseAgreementService leaseAgreementService;
    @Scheduled(cron = "0 0 0 * * *")
    public void checkLeaseStatus(){
        LambdaUpdateWrapper<LeaseAgreement> updateWrapper=new LambdaUpdateWrapper<>();
        Date now=new Date();
        updateWrapper.le(LeaseAgreement::getLeaseEndDate,now);
        updateWrapper.eq(LeaseAgreement::getStatus,LeaseStatus.SIGNED);
        updateWrapper.in(LeaseAgreement::getStatus,LeaseStatus.SIGNED,LeaseStatus.WITHDRAWING);
        leaseAgreementService.update(updateWrapper);
    }

}
